/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.ViewSupplierDetailSummary;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.ViewSupplierDetailSummaryDao;
import com.ruipengkj.service.ViewSupplierDetailSummaryService;
/**
 * 说明：
 * 供货单明细汇总表Service层接口实现
 * @Author：李智深
 * @Date：2012-03-16
 */
@Service
public class ViewSupplierDetailSummaryServiceImpl implements ViewSupplierDetailSummaryService{

	@Resource
	private ViewSupplierDetailSummaryDao ViewSupplierDetailSummaryDao;//DAO层
	
	//根据条件查询
	@Override
	public List<ViewSupplierDetailSummary> findService(ViewSupplierDetailSummary entity) throws Exception {
		String hql = "select o from ViewSupplierDetailSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewSupplierDetailSummaryDao.findDao(hql, whereHQL.toString(), param, orderby);
	}

	//根据ID翻页查询
	@Override
	public PageModel<ViewSupplierDetailSummary> getScrollService(int firstResult,
			int maxResult, ViewSupplierDetailSummary entity) throws Exception {
		String hql = "select o from ViewSupplierDetailSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getSupplierName()!=null&&!entity.getSupplierName().equals("")){
				whereHQL.append("o.supplierName").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getSupplierName()+"%");
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewSupplierDetailSummaryDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	//修改
	@Override
	public void modifyService(ViewSupplierDetailSummary entity) throws Exception {
		ViewSupplierDetailSummaryDao.modifyDao(entity);
		
	}
	//添加
	@Override
	public void saveService(ViewSupplierDetailSummary entity) throws Exception {
		ViewSupplierDetailSummaryDao.saveDao(entity);
	}

	//根据ID删除
	@Override
	public void deleteService(String id) throws Exception {
		ViewSupplierDetailSummaryDao.deleteDao(id);
		
	}
	//根据ID查询
	@Override
	public ViewSupplierDetailSummary getByIdService(String id) throws Exception {
		return ViewSupplierDetailSummaryDao.getByIdDao(id);
	}
	//添加或修改
	@Override
	public void saveOrUpdateService(ViewSupplierDetailSummary entity) throws Exception {
		ViewSupplierDetailSummaryDao.saveOrUpdateDao(entity);
	}
	//添加返回ID
	@Override
	public Serializable saveRetService(ViewSupplierDetailSummary entity) throws Exception {
		return ViewSupplierDetailSummaryDao.saveRetDao(entity);
	}

	public ViewSupplierDetailSummaryDao getViewSupplierDetailSummaryDao() {
		return ViewSupplierDetailSummaryDao;
	}

	public void setViewSupplierDetailSummaryDao(
			ViewSupplierDetailSummaryDao ViewSupplierDetailSummaryDao) {
		this.ViewSupplierDetailSummaryDao = ViewSupplierDetailSummaryDao;
	}

	@Override
	public List<ViewSupplierDetailSummary> findExportService(
			ViewSupplierDetailSummary entity) throws Exception {
		String hql = "select o from ViewSupplierDetailSummary o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getSupplierName()!=null&&!entity.getSupplierName().equals("")){
				whereHQL.append("o.supplierName").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
				param.add("%"+entity.getSupplierName()+"%");
			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return ViewSupplierDetailSummaryDao.findDao(hql, whereHQL.toString(), param, orderby);
	}
}
